use actix_web::{ web};
use crate::{controller::{socket::socket_handler, upload::upload, user}, middleware::auth};

pub fn init_routes(cfg: &mut web::ServiceConfig) {
    let cfg = cfg
    .service(actix_files::Files::new("/assets", "./assets").show_files_listing());
    not_auth_routes(cfg);
    need_auth_routes(cfg);
}
fn not_auth_routes(cfg: &mut web::ServiceConfig) {
    cfg
    .route("/", web::get().to(|| async { "hello actix-web" }));
}
fn need_auth_routes(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("")
        .wrap(auth::Auth)
        .route("/ws", web::get().to(socket_handler))
        .route("/upload", web::post().to(upload))
        .service(
            web::scope("user")
            .route("/list", web::get().to(user::list))
        )
    );
}